/*
 * USART_INTERFACE.cpp
 *
 * last modification: 2013-12-19
 * author: Marcin Lepczyk
 */

#include <avr/io.h>
#include "../inc/USART_INTERFACE.h"

//constructor
USART_INTERFACE::USART_INTERFACE(uint16_t block_size)
{
	//setting pin configuration
	PORTD_OUTCLR = PIN2_bm;
	PORTD_OUTSET = PIN3_bm;
	PORTD_DIRSET = PIN3_bm;
	//setting USART configuration
	USARTD0.CTRLC = USART_CHSIZE_8BIT_gc;
	USARTD0.CTRLC |= USART_PMODE_EVEN_gc;
	USARTD0.BAUDCTRLA = 0xF5;
	USARTD0.BAUDCTRLB = 0xCC;
	//setting DMA configuration
	DMA.CH0.DESTADDR0 = (uint8_t)(uint16_t)&USARTD0_DATA;
	DMA.CH0.DESTADDR1 = ((uint16_t)&USARTD0_DATA)>>8;
	DMA.CH0.DESTADDR2 = 0;
	/*DMA.CH0.SRCADDR0
	DMA.CH0.SRCADDR1 */	
	DMA.CH0.SRCADDR2 = 0;
	DMA.CH0.CTRLA = DMA_CH_BURSTLEN_1BYTE_gc;
	/*DMA.CH1.DESTADDR0
	DMA.CH1.DESTADDR1 */
	DMA.CH1.DESTADDR2 = 0;
	DMA.CH1.SRCADDR0 = (uint8_t)(uint16_t)&USARTD0_DATA;
	DMA.CH1.SRCADDR1 = ((uint16_t)&USARTD0_DATA)>>8;
	DMA.CH1.SRCADDR2 = 0;
	
	DMA.CTRL = DMA_ENABLE_bm;
}
